﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ToMIC.Identity
{
    public class EmailingList
    {
        private List<EmailContact> _emailingList { get; set; }
        public EmailingList()
        {
            _emailingList = new List<EmailContact>();
        }

        public void Add(EmailContact contact)
        {
            _emailingList.Add(contact);
        }

        public override string ToString()
        {
            var sb = new StringBuilder();
            foreach (var item in _emailingList)
            {
                sb.AppendLine(item.ToString());
            }

            return sb.ToString();
        }

        public static EmailingList Parse(string s)
        {
            var emailingList = new EmailingList();
            var list = s.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var item in list)
            {
                emailingList.Add(EmailContact.Parse(item));
            }

            return emailingList;
        }
    }
}
